//
//  YpViewController.m
//  KIASupervisory
//
//  Created by apple on 15/7/19.
//  Copyright (c) 2015年 MyCompany. All rights reserved.
//

#import "WeixViewController.h"
#import "WeixListViewController.h"
#import "PingjiaViewController.h"
#import "MainViewController.h"
#import "SXDetailModel.h"
#import "SXDetailImgModel.h"
#import "SXHTTPManager.h"
#import "YMShowImageView.h"
#import "YMTapGestureRecongnizer.h"
#import "SJAvatarBrowser.h"
#import "UIImageView+WebCache.h"

@interface WeixViewController ()<UIGestureRecognizerDelegate>

@property (nonatomic, strong) NSMutableArray *ypList;

@property (weak, nonatomic) IBOutlet UILabel *idLbl;
@property (weak, nonatomic) IBOutlet UILabel *titleLbl;

@property (weak, nonatomic) IBOutlet UILabel *baoxTelLbl;
@property (weak, nonatomic) IBOutlet UILabel *baoxLbl;
@property (weak, nonatomic) IBOutlet UILabel *baoxNoteLbl;
@property (weak, nonatomic) IBOutlet UILabel *baoxDateLbl;
@property (weak, nonatomic) IBOutlet UILabel *baoxRenLbl;
@property (weak, nonatomic) IBOutlet UILabel *shenhDateLbl;
@property (weak, nonatomic) IBOutlet UILabel *shenhNoteLbl;
@property (weak, nonatomic) IBOutlet UILabel *weixDateLbl;
@property (weak, nonatomic) IBOutlet UILabel *weixNoteLbl;
@property (weak, nonatomic) IBOutlet UIImageView *image1;
@property (weak, nonatomic) IBOutlet UIImageView *image2;
@property (weak, nonatomic) IBOutlet UIImageView *image3;
@property (weak, nonatomic) IBOutlet UIView *state2;
@property (weak, nonatomic) IBOutlet UIView *state3;
@property (weak, nonatomic) IBOutlet UIView *imageView;


@property (nonatomic,strong) SXDetailModel *detailModel;
@property (nonatomic, strong) NetworkManager *networkManager;
@property (nonatomic, strong) MBProgressHUD *HUD;

@end

@implementation WeixViewController

@synthesize dataList = _dataList;
@synthesize showData = _showData;

- (void)viewDidLoad
{
    [self.navigationController setNavigationBarHidden:YES];
    self.networkManager = [[NetworkManager alloc] init];
    self.detailModel = [[SXDetailModel alloc] init];
    self.HUD = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:self.HUD];
    self.HUD.delegate = self;
    [super viewDidLoad];
    NSDictionary *data = self.wzInfo;
    NSLog(@"data: %@",data);
    NSString *id = [data objectForKeyOrNil:@"id"];
    NSString *title = [data objectForKeyOrNil:@"title"];
    NSString *unicodeStr = [title stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    self.titleLbl.text = unicodeStr;
    [self getContent:id];
    
}

- (IBAction)backToPre:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}

/**
 *受理
 **/
- (IBAction)weixiuChuli:(id)sender {
    
    UserInfo *user = [UserInfo instance];
    UIButton *shouli = (UIButton *)[self.view viewWithTag:110];
    NSString *user_type = [user.info objectForKey:@"roleName"];
    if([user_type isEqualToString:@"维修人员"]){
        if([shouli.currentTitle isEqualToString:@"受  理"]){
            NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [self.wzInfo objectForKeyOrNil:@"id"],@"weixiu_id",
                                   [user.info objectForKey:@"id"] ,@"weix_ren_id",
                                   [user.info objectForKey:@"fullName"] ,@"weix_ren",nil];
            [self.networkManager requestWithMethod:weixiuChuli parameter:param delegate:self];
            [self.HUD show:YES];
        } else if([shouli.currentTitle isEqualToString:@"已完成"] || [shouli.currentTitle isEqualToString:@"重新提交"]){
            NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                                   [self.wzInfo objectForKeyOrNil:@"id"],@"weixiu_id",nil];
            [self.networkManager requestWithMethod:finishWeixiu parameter:param delegate:self];
            [self.HUD show:YES];
        }
 
    }
 
}

/**
  通过
 */
- (IBAction)tongguo:(id)sender {
    UserInfo *user = [UserInfo instance];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                           [self.wzInfo objectForKeyOrNil:@"id"],@"weixiu_id",
                           @"1",@"shenh_state",
                           [user.info objectForKey:@"fullName"], @"shenh_ren",
                            nil];
    [self.networkManager requestWithMethod:wancWeixiu parameter:param delegate:self];
    [self.HUD show:YES];
}

/**
 驳回
 */
- (IBAction)bohui:(id)sender {
    UserInfo *user = [UserInfo instance];
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                           [self.wzInfo objectForKeyOrNil:@"id"],@"weixiu_id",
                           @"0",@"shenh_state",
                           [user.info objectForKey:@"fullName"], @"shenh_ren",
                           nil];
    [self.networkManager requestWithMethod:wancWeixiu parameter:param delegate:self];
    [self.HUD show:YES];
    
}

- (IBAction)telphone:(id)sender {
    NSString *num = [[NSString alloc]initWithFormat:@"telprompt://%@",self.baoxTelLbl.text]; //而这个方法则打电话前先弹框 是否打电话 然后打完电话之后回到程序中 网上说这个方法可能不合法 无法通过审核
    num = [num stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning]; 
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
   
    
}

//根据已有数据刷新界面
- (void)updateViewWithData {
    NSDictionary *data = self.wzInfo;
    NSLog(@"data: %@",data);
    NSString *id = [data objectForKeyOrNil:@"id"];
    NSString *title = [data objectForKeyOrNil:@"title"];
    //    NSString *sendDate = [data objectForKeyOrNil:@"sendDate"];
    NSString *weiz = [data objectForKeyOrNil:@"weiz"];
    NSString *title_weiz ;
    title_weiz = [@"位置: " stringByAppendingString:weiz];
    NSString *unicodeStr = [title stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    self.titleLbl.text = unicodeStr;
    [self getContent:id];
}

-(void) getContent:(NSString*)id {
     NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:
                           id,@"weixiu_id", nil];
    [self.networkManager requestWithMethod:weixiuDetail parameter:param delegate:self];
    [self.HUD show:YES];
}


- (void)refreshViewByReloadData {
    [self getYpList];
}

- (void)getYpList {
    [self.ypList removeAllObjects];
}

- (void)network:(NetworkManager *)net methodId:(RequestMethodId)methodId didRequestFinishedWithResult:(id)data {
    [self.HUD hide:YES];
     UserInfo *user = [UserInfo instance];
     if (methodId == weixiuDetail) {
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSString * result = [data objectForKeyOrNil:@"result"]; 
            if([result isEqualToString:@"000"]){
                NSArray *results = [data objectForKeyOrNil:@"weixiu"];
                if (![results isKindOfClass:[NSNull class]] && [results count] > 0) {
                    NSString *baoxNote = [results valueForKey:@"baoxNote"];
                    NSString *baoxDate = [results valueForKey:@"baoxDate"];
                    //NSString *cuixState = [results valueForKey:@"cuixState"];
                    baoxNote = [@"详情: " stringByAppendingString:baoxNote];
                    NSString *unicodeBaoxNote = [baoxNote stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    self.baoxLbl.text = unicodeBaoxNote;
                    self.baoxTelLbl.text = [results valueForKey:@"baoxRenPhone"];
                    self.baoxRenLbl.text = [results valueForKey:@"baoxRen"];
                    
                    self.baoxDateLbl.text = baoxDate;
                    NSString *user_type = [user.info objectForKey:@"roleName"];
                    UIButton *shouli = (UIButton *)[self.view viewWithTag:110];
                    UIButton *tongguo = (UIButton *)[self.view viewWithTag:111];
                    UIButton *bohui = (UIButton *)[self.view viewWithTag:112];
                    NSArray *picsArray = [[results valueForKey:@"pics"] componentsSeparatedByString:@","];
                    NSLog(@"@@@@@%@",picsArray);
                    NSLog(@"@@@@@%lu",(unsigned long)picsArray.count);
//                    NSString *pathStr = @"http://www.51ber.com/zhihuiguanjia/upload/weixiu/";
                    int count = picsArray.count;//减少调用次数
                    NSString *image1Str,*image2Str,*image3Str;
                    for( int i=0; i<count; i++){
                        NSLog(@"%i-%@", i, [picsArray objectAtIndex:i]);
                        if(i==0){
                            image1Str = [NSString stringWithFormat:@"%@%@",SERVER_PATH,[picsArray objectAtIndex:i]];
                            
                        } else if(i==1){
                            image2Str = [NSString stringWithFormat:@"%@%@",SERVER_PATH,[picsArray objectAtIndex:i]];
                        } else if (i==2){
                            image2Str = [NSString stringWithFormat:@"%@%@",SERVER_PATH,[picsArray objectAtIndex:i]];
                        }
                    } 
                    if(count==1 && [[picsArray objectAtIndex:0] isEqualToString:@""]){
                        UILabel *wuTupian = (UILabel *)[self.view viewWithTag:120];
                        wuTupian.hidden = NO;
                        UIButton *img1 = (UIButton *)[self.view viewWithTag:201];
                        img1.userInteractionEnabled= NO;
                        UIButton *img2 = (UIButton *)[self.view viewWithTag:202];
                        img2.userInteractionEnabled= NO;
                        UIButton *img3 = (UIButton *)[self.view viewWithTag:203];
                        img3.userInteractionEnabled= NO;
                    } else {
                        NSURL *url1 = [NSURL URLWithString:image1Str];
                        NSLog(@"@@@@%@",image1Str);
                        [_image1 sd_setImageWithURL:url1];
                       
                        //覆盖方法，指哪打哪，这个方法是下载imagePath2的时候响应
                        SDWebImageManager *manager = [SDWebImageManager sharedManager];
                        
                        [manager downloadImageWithURL:url1 options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {

                        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                        }];

                        }
                    if(image2Str==nil){
                        UIButton *img2 = (UIButton *)[self.view viewWithTag:202];
                        img2.userInteractionEnabled= NO;
                    } else {
                        NSURL *url2 = [NSURL URLWithString:image2Str];

                        [_image2 sd_setImageWithURL:url2];
                        
                        //覆盖方法，指哪打哪，这个方法是下载imagePath2的时候响应
                        SDWebImageManager *manager = [SDWebImageManager sharedManager];
                        
                        [manager downloadImageWithURL:url2 options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) {
                            
                        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                        }];
                        
                    }
                    if(image3Str==nil){
                        UIButton *img3 = (UIButton *)[self.view viewWithTag:203];
                        img3.userInteractionEnabled= NO;
                    } else {
                        NSURL *url3 = [NSURL URLWithString:image3Str];
                        [_image3 sd_setImageWithURL:url3];
                        //覆盖方法，指哪打哪，这个方法是下载imagePath2的时候响应
                        SDWebImageManager *manager = [SDWebImageManager sharedManager];
                        [manager downloadImageWithURL:url3 options:SDWebImageRetryFailed progress:^(NSInteger receivedSize, NSInteger expectedSize) { 
                        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
                        }];
                    }
                    if([[results valueForKey:@"state" ] intValue] == 1){
                        NSLog(@"@@@@@@user_type%@",user_type);
                        if([user_type isEqualToString:@"维修人员"]){
                            shouli.hidden = NO;
                        }else if([user_type isEqualToString:@"维修管理员"]){
                            tongguo.hidden = YES;
                            bohui.hidden = YES;
                            self.baoxNoteLbl.text = @"业主申请了新的维修任务,请维修人员受理";
                        }else {
                            self.baoxNoteLbl.text = @"业主申请了新的维修任务,请维修人员受理";
                        }
                    }
                    else if([[results valueForKey:@"state" ] intValue] == 2){
                        self.state2.hidden = NO;
//                        NSString *weixNote = [results valueForKey:@"weixNote"];
//                        NSString *unicodewWeixNote = [weixNote stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//                        self.weixNoteLbl.text = unicodewWeixNote;
//                        self.weixDateLbl.text = [results valueForKey:@"weixDate"];
                        NSLog(@"@@@@%@",user_type);
                        if([user_type isEqualToString:@"维修人员"]){
                            shouli.hidden = NO;
                            [shouli setTitle:@"已完成" forState:UIControlStateNormal];
                        }else if([user_type isEqualToString:@"维修管理员"]){
                            self.baoxNoteLbl.text = @"业主申请了新的维修任务,请维修人员受理";
                            self.weixNoteLbl.text = [[results valueForKey:@"weixRen" ]stringByAppendingString:@"受理了此次维修任务，如果完成请审核" ];
                            self.weixDateLbl.text = [results valueForKey:@"weixDate"];
                            tongguo.hidden = YES;
                            bohui.hidden = YES;
                        } else {
                            self.baoxNoteLbl.text = @"业主申请了新的维修任务,请维修人员受理";
                            self.weixNoteLbl.text = [[results valueForKey:@"weixRen" ]stringByAppendingString:@"受理了此次维修任务，如果完成请审核" ];
                            self.weixDateLbl.text = [results valueForKey:@"weixDate"];
                            tongguo.hidden = YES;
                            bohui.hidden = YES;
                        }
                        
                        
                        
                    } else if([[results valueForKey:@"state" ] intValue] == 3){
                        self.state2.hidden = NO;
                        NSString *weixNote = [results valueForKey:@"weixNote"];
                        NSString *unicodewWeixNote = [weixNote stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                        NSString *shenhNote = [results valueForKey:@"shenhNote"];
                        NSString *unicodeShenhNote = [shenhNote stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                        self.weixNoteLbl.text = unicodewWeixNote;
                        self.weixDateLbl.text = [results valueForKey:@"weixDate"];
                        self.state3.hidden = NO;
                        if([user_type isEqualToString:@"维修人员"]){
                            shouli.hidden = YES;
                            self.weixNoteLbl.text = @"您已提交审核此维修任务,待领导审核" ;
                        } else if([user_type isEqualToString:@"维修管理员"]){
                            tongguo.hidden = YES;
                            bohui.hidden = YES;
                            self.weixNoteLbl.text = [[results valueForKey:@"weixRen" ]stringByAppendingString:@"受理了此次维修任务,请审核" ];
                        } else {
                            shouli.hidden = YES;
                            self.weixNoteLbl.text = [[results valueForKey:@"weixRen" ]stringByAppendingString:@"受理了此次维修任务,等待领导审核" ];
                        }
                        
                        if([[results valueForKey:@"shenhState"] intValue] == 1){
                            self.shenhNoteLbl.text = [[results valueForKey:@"shenhRen"] stringByAppendingString:@"通过了此次维修任务,等待业主评价" ];
                            self.shenhDateLbl.text = [results valueForKey:@"shenhDate"];
                            
                            
                        } else if([[results valueForKey:@"shenhState"] intValue] == 0){
                            if([user_type isEqualToString:@"维修人员"]){
                                
                                self.shenhDateLbl.text = [results valueForKey:@"shenhDate"];
                                if([[user.info objectForKey:@"fullName"] isEqualToString:[results valueForKey:@"weixRen"]]){
                                    self.shenhNoteLbl.text = [[results valueForKey:@"shenhRen"] stringByAppendingString:@"驳回了此次维修任务,请重新提交" ];
                                    shouli.hidden = NO;
                                    [shouli setTitle:@"重新提交" forState:UIControlStateNormal];
                                } else {
                                    self.shenhNoteLbl.text = [[results valueForKey:@"shenhRen"] stringByAppendingString:@"驳回了此次维修任务" ];
                                }
                            } else if([user_type isEqualToString:@"维修管理员"]){
                                self.shenhNoteLbl.text = [[results valueForKey:@"shenhRen"] stringByAppendingString:@"驳回了此次维修任务" ];
                                self.shenhDateLbl.text = [results valueForKey:@"shenhDate"];
                            } else {
                                self.shenhNoteLbl.text = [[results valueForKey:@"shenhRen"] stringByAppendingString:@"驳回了此次维修任务" ];
                                self.shenhDateLbl.text = [results valueForKey:@"shenhDate"];
                            }
                            
                        }
                    }
                    else if([[results valueForKey:@"state" ] intValue] == 4){
                        self.state2.hidden = NO;
                        NSString *weixNote = [results valueForKey:@"weixNote"];
                        //NSString *unicodewWeixNote = [weixNote stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                        //NSString *shenhNote = [results valueForKey:@"shenhNote"];
//                        NSString *unicodeShenhNote = [shenhNote stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                        self.weixDateLbl.text = [results valueForKey:@"weixDate" ];
                        
                        self.state3.hidden = YES;
                        if([user_type isEqualToString:@"维修人员"]){
                            shouli.hidden = YES;
                            self.weixNoteLbl.text = @"您已提交审核此维修任务,待领导审核" ;
                        } else if([user_type isEqualToString:@"维修管理员"]){
                            tongguo.hidden = NO;
                            bohui.hidden = NO;
                            self.weixNoteLbl.text = [[results valueForKey:@"weixRen" ]stringByAppendingString:@"受理了此次维修任务,请审核" ];
                        } else {
                            shouli.hidden = YES;
                            self.weixNoteLbl.text = [[results valueForKey:@"weixRen" ]stringByAppendingString:@"受理了此次维修任务,等待领导审核" ];
                        }
                        
                        
//                        if([[results valueForKey:@"shenhState"] intValue] == 1){
//                            self.shenhNoteLbl.text = unicodeShenhNote;
//                            self.shenhDateLbl.text = [results valueForKey:@"shenhDate"];
//                        } else if([[results valueForKey:@"shenhState"] intValue] == 2){
//                            self.shenhNoteLbl.text = unicodeShenhNote;
//                            self.shenhDateLbl.text = [results valueForKey:@"shenhDate"];
//                        }
                    }
                }
            }
        }
        
    } else if(methodId == weixiuChuli){
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSString * result = [data objectForKeyOrNil:@"result"];
             if([result isEqualToString:@"000"]){
                NSString * resultinfo = [data objectForKeyOrNil:@"resultinfo"];
                NSString *unicodeStr = [resultinfo stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                                message:unicodeStr
                                                               delegate:nil
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:nil];
                [alert show];
                NSString *cuixiu = @"您已经受理了此维修，请及时完成维修";
                NSString *unicodeBaoxNote = [cuixiu stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                self.baoxNoteLbl.text = unicodeBaoxNote;
                [self.navigationController popViewControllerAnimated:YES];
            } else if([result isEqualToString:@"001"]){
                NSString * resultinfo = [data objectForKeyOrNil:@"resultinfo"];
                NSString *unicodeStr = [resultinfo stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                                message:unicodeStr
                                                               delegate:nil
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:nil];
                [alert show];
            }
        }
    }
    else if(methodId == finishWeixiu){
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSString * result = [data objectForKeyOrNil:@"result"];
            if([result isEqualToString:@"000"]){
                NSString * resultinfo = [data objectForKeyOrNil:@"resultinfo"];
                NSString *unicodeStr = [resultinfo stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                                message:unicodeStr
                                                               delegate:nil
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:nil];
                [alert show];
                NSString *cuixiu = @"您已经完成此维修，已提交领导审核";
                NSString *unicodeWeixNote = [cuixiu stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                self.weixNoteLbl.text = unicodeWeixNote;
                UIButton *shouli = (UIButton *)[self.view viewWithTag:110];
                shouli.hidden = YES;
                [self.navigationController popViewControllerAnimated:YES];
                
            } else if([result isEqualToString:@"001"]){
                NSString * resultinfo = [data objectForKeyOrNil:@"resultinfo"];
                NSString *unicodeStr = [resultinfo stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                                message:unicodeStr
                                                               delegate:nil
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:nil];
                [alert show];
            }
        }
    } else if(methodId == wancWeixiu){
        if ([data isKindOfClass:[NSDictionary class]]) {
            NSString * result = [data objectForKeyOrNil:@"result"];
            if([result isEqualToString:@"000"]){
                NSString * resultinfo = [data objectForKeyOrNil:@"resultinfo"];
                NSString *unicodeStr = [resultinfo stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                                message:unicodeStr
                                                               delegate:nil
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:nil];
                [alert show];
                NSString *cuixiu = @"您已经完成此维修，已提交领导审核";
                NSString *unicodeWeixNote = [cuixiu stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                self.weixNoteLbl.text = unicodeWeixNote;
                UIButton *shouli = (UIButton *)[self.view viewWithTag:110];
                shouli.hidden = YES;
                [self.navigationController popViewControllerAnimated:YES];
                
            } else if([result isEqualToString:@"001"]){
                NSString * resultinfo = [data objectForKeyOrNil:@"resultinfo"];
                NSString *unicodeStr = [resultinfo stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                                message:unicodeStr
                                                               delegate:nil
                                                      cancelButtonTitle:@"确定"
                                                      otherButtonTitles:nil];
                [alert show];
            }
        }
        
    }
    
}

// 定义成方法方便多个label调用 增加代码的复用性
- (CGSize)sizeWithString:(NSString *)string font:(UIFont *)font
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(320, 8000)//限制最大的宽度和高度
                                       options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading  |NSStringDrawingUsesLineFragmentOrigin//采用换行模式
                                    attributes:@{NSFontAttributeName: font}//传人的字体字典
                                       context:nil];
    
    return rect.size;
}

#pragma mark - 图片点击事件回调
- (void)showImageViewWithImageViews:(NSArray *)imageViews byClickWhich:(NSInteger)clickTag{
    
    UIView *maskview = [[UIView alloc] initWithFrame:self.view.bounds];
    maskview.backgroundColor = [UIColor blackColor];
    [self.view addSubview:maskview];
    
    YMShowImageView *ymImageV = [[YMShowImageView alloc] initWithFrame:self.view.bounds byClick:clickTag appendArray:imageViews];
    [ymImageV show:maskview didFinish:^(){
        
        [UIView animateWithDuration:0.5f animations:^{
            
            ymImageV.alpha = 0.0f;
            maskview.alpha = 0.0f;
            
        } completion:^(BOOL finished) {
            
            [ymImageV removeFromSuperview];
            [maskview removeFromSuperview];
        }];
        
    }];
    
}



- (void)network:(NetworkManager *)net methodId:(RequestMethodId)methodId didRequestFailedWithError:(NSError *)error {
    [self.HUD hide:YES];
    //[self endRefresh];
    //self.isRefreshing = NO;
    
    NSDictionary *errorInfo = error.userInfo;
    NSString *msg = [errorInfo objectForKeyOrNil:@"errorMsg"];
    
    NSInteger code = error.code;
    if (code != 1) {
        if ([msg length] == 0) {
            msg = @"数据获取失败，请稍后重试";
        }
    }
    
    if ([msg length] > 0) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
                                                        message:msg
                                                       delegate:nil
                                              cancelButtonTitle:@"确定"
                                              otherButtonTitles:nil];
        [alert show];
    }
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_showData count]>0?[_showData count]:0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *TableSampleIdentifier = @"TableSampleIdentifier";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
                             TableSampleIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]
                initWithStyle:UITableViewCellStyleDefault
                reuseIdentifier:TableSampleIdentifier];
    }
    if (_showData != nil && _showData.count >0) {
        NSUInteger row = [indexPath row];
        cell.textLabel.text = [_showData objectAtIndex:row];
    }
    return cell;
}

- (IBAction)magnifyImage1:(id)sender {
    [SJAvatarBrowser showImage:_image1];//调用方法
}

- (IBAction)magnifyImage2:(id)sender {
    [SJAvatarBrowser showImage:_image2];//调用方法
}

- (IBAction)magnifyImage3:(id)sender {
    [SJAvatarBrowser showImage:_image3];//调用方法
}


@end

